package com.united.ucts.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.united.frame.common.module.service.impl.BaseServiceImpl;
import com.united.ucts.modules.system.mybatis.mapper.ResourceCategoryMapper;
import com.united.ucts.modules.system.pojo.po.ResourceCategory;
import com.united.ucts.modules.system.service.ResourceCategoryService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 后台资源分类管理Service实现类
 */
@Service
public class ResourceCategoryServiceImpl extends BaseServiceImpl<ResourceCategoryMapper, ResourceCategory> implements ResourceCategoryService {

    @Override
    public List<ResourceCategory> listAll() {
        LambdaQueryWrapper<ResourceCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(ResourceCategory::getSort);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public int create(ResourceCategory umsResourceCategory) {
        umsResourceCategory.setCreateTime(LocalDateTime.now());
        return this.baseMapper.insert(umsResourceCategory);
    }

    @Override
    public int update(String id, ResourceCategory umsResourceCategory) {
        umsResourceCategory.setId(id);
        return this.baseMapper.updateById(umsResourceCategory);
    }

    @Override
    public int delete(String id) {
        return this.baseMapper.deleteById(id);
    }
}